package com.amos.generate.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Copyright © 2018 嘉源锐信. All rights reserved.
 *
 * @Project: mu-exam
 * @ClassName: SpringContext
 * @Package: com.amos.generate.util
 * @author: zhuqb
 * @Description: 获取ApplicationContext上下文 v
 * @date: 2020/3/11 0011 上午 8:54
 * @Version: V1.0
 */
@Component
public class SpringContext implements ApplicationContextAware {

    private static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContext.context = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz){
        return context.getBean(clazz);
    }

    public static <T> T getBean(String clazzName) {
        return (T)context.getBean(clazzName);
    }
}
